This invention relates to runtime analysis of computer programs, also known as dynamic analysis. This invention more particularly relates to detection of thread starvation and, more particularly, to detection of thread starvation in a running computer program that has been instrumented such that the program's system calls are intercepted for use during runtime analysis to detect thread starvation in the running program.
Thread starvation occurs whenever few or no CPU cycles are available to execute a particular thread in a program. This situation typically arises when threads of mixed priorities are created, if the higher-priority threads hog the CPU while locks are held.
A real-world scenario in which thread starvation occurs is when a relatively low-priority thread requires one or more locks that are often held by relatively high-priority threads. In this scenario, the lower-priority thread is starved during time intervals in which a higher-priority thread is holding a lock required by the lower-priority thread, more often than not, when time slices arrive during which the lower-priority thread could have executed.
Another situation in which thread starvation occurs is when a relatively low-priority thread holds a lock while relatively high-priority threads waiting for that lock consume CPU cycles. In this scenario, the lower-priority thread is starved during time intervals in which one or more higher-priority threads are busily waiting for a lock held by the lower-priority thread, so that the lower-priority thread runs only during rarely available time slices.
Depending on the operating system, the above scenarios can cause necessary execution to be postponed much longer than necessary. Or, that execution may not occur at all. A software application's behavior while thread starvation occurs, as perceived by its user, may be hung up, or it may have very slow progress, or it may fail to produce a result within an expected timeframe.
To figure out why performance is draggy, developers deploy runtime analysis tools to analyze software application behavior. The typical tool of choice is a performance profiling tool. However, current profiling tools do not indicate thread starvation as a cause of poor performance. Thus, it is up to a software application's developers to figure out when thread starvation is causing poor performance. For some performance profiling tools, the profiling results may point out functions called by the starved thread, indicating that those functions run slowly, but there is no indication of why those functions run slowly. For other tools, which calculate time spent by summing up clock cycles per instruction, the slowly-running functions executed by the starved thread may not be indicated at all in the profiling results.